package com.kunlun.system.model;

import com.kunlun.common.model.monitor.CpuInfoModel;
import com.kunlun.common.model.monitor.DiskInfoModel;
import com.kunlun.common.model.monitor.JvmInfoModel;
import com.kunlun.common.model.monitor.MemoryInfoModel;
import com.kunlun.common.model.monitor.NetworkInfoModel;
import com.kunlun.common.model.monitor.SystemDataModel;
import com.kunlun.common.model.monitor.SystemInfoModel;
import com.kunlun.common.utils.CalculateUtil;
import com.kunlun.common.utils.CommonUtil;
import org.springframework.util.ObjectUtils;

import java.util.Date;
import java.util.List;

/**
 * 系统监控数据模型
 */
public class SystemMachineModel {

    // 主键ID
    private String id;

    // 服务名
    private String serviceName;

    // ip地址
    private String ipAddress;

    // CPU逻辑处理器数
    private int cpuLogicalProcessorCount;

    // CPU物理处理器数
    private int cpuPhysicalProcessorCount;

    // CPU系统使用率
    private String cpuSystemUsedPercent;

    // CPU用户使用率
    private String cpuUserUsedPercent;

    // CPU等待率
    private String cpuWaitPercent;

    // CPU使用率
    private String cpuUsedPercent;

    // 内存总容量
    private String memoryTotal;

    // 内存空闲量
    private String memoryFree;

    // 内存使用量
    private String memoryUsed;

    // 内存使用率
    private String memoryUsedPercent;

    // 磁盘文件系统类型
    private String diskType;

    // 磁盘总容量
    private String diskTotalSpace;

    // 磁盘总大小
    private String diskTotalSize;

    // 磁盘可用容量
    private String diskUsableSpace;

    // 磁盘可用大小
    private String diskUsableSize;

    // 磁盘已使用大小
    private String diskUsedSize;

    // 磁盘使用率
    private String diskUsedPercent;

    private Date createTime;

    private Date modifiedTime;

    public SystemMachineModel() {
    }

    public SystemMachineModel(SystemDataModel systemDataModel) {
        this.id = CommonUtil.generateUUID();
        this.serviceName = systemDataModel.getServiceName();
        CpuInfoModel cpuInfoModel = systemDataModel.getCpuInfoModel();
        MemoryInfoModel memoryInfoModel = systemDataModel.getMemoryInfoModel();
        DiskInfoModel diskInfoModel = systemDataModel.getDiskInfoModel();
        SystemInfoModel systemInfoModel = systemDataModel.getSystemInfoModel();
        if (!ObjectUtils.isEmpty(systemInfoModel)) {
            this.ipAddress = systemInfoModel.getIp();
        }
        if (!ObjectUtils.isEmpty(cpuInfoModel)) {
            this.cpuLogicalProcessorCount = cpuInfoModel.getLogicalProcessorCount();
            this.cpuPhysicalProcessorCount = cpuInfoModel.getPhysicalProcessorCount();
            this.cpuSystemUsedPercent = String.valueOf(cpuInfoModel.getSystemPercent());
            this.cpuUserUsedPercent = String.valueOf(cpuInfoModel.getUserPercent());
            this.cpuWaitPercent = String.valueOf(cpuInfoModel.getWaitPercent());
            this.cpuUsedPercent = String.valueOf(cpuInfoModel.getUsePercent());
        }
        if (!ObjectUtils.isEmpty(memoryInfoModel)) {
            this.memoryTotal = memoryInfoModel.getTotal();
            this.memoryFree = memoryInfoModel.getFree();
            this.memoryUsed = memoryInfoModel.getUsed();
            this.memoryUsedPercent = String.valueOf(memoryInfoModel.getUsePercent());
        }
        if (!ObjectUtils.isEmpty(diskInfoModel)) {
            this.diskType = diskInfoModel.getType();
            this.diskTotalSpace = String.valueOf(diskInfoModel.getTotalSpace());
            this.diskTotalSize = diskInfoModel.getSize() + "GB";
            this.diskUsableSpace = String.valueOf(diskInfoModel.getUsableSpace());
            this.diskUsableSize = diskInfoModel.getUsed() + "GB";
            this.diskUsedSize = diskInfoModel.getUsed() + "GB";
            this.diskUsedPercent = diskInfoModel.getUsePercent();
        }
        this.createTime = new Date();
        this.modifiedTime = new Date();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public int getCpuLogicalProcessorCount() {
        return cpuLogicalProcessorCount;
    }

    public void setCpuLogicalProcessorCount(int cpuLogicalProcessorCount) {
        this.cpuLogicalProcessorCount = cpuLogicalProcessorCount;
    }

    public int getCpuPhysicalProcessorCount() {
        return cpuPhysicalProcessorCount;
    }

    public void setCpuPhysicalProcessorCount(int cpuPhysicalProcessorCount) {
        this.cpuPhysicalProcessorCount = cpuPhysicalProcessorCount;
    }

    public String getCpuSystemUsedPercent() {
        return cpuSystemUsedPercent;
    }

    public void setCpuSystemUsedPercent(String cpuSystemUsedPercent) {
        this.cpuSystemUsedPercent = cpuSystemUsedPercent;
    }

    public String getCpuUserUsedPercent() {
        return cpuUserUsedPercent;
    }

    public void setCpuUserUsedPercent(String cpuUserUsedPercent) {
        this.cpuUserUsedPercent = cpuUserUsedPercent;
    }

    public String getCpuWaitPercent() {
        return cpuWaitPercent;
    }

    public void setCpuWaitPercent(String cpuWaitPercent) {
        this.cpuWaitPercent = cpuWaitPercent;
    }

    public String getCpuUsedPercent() {
        return cpuUsedPercent;
    }

    public void setCpuUsedPercent(String cpuUsedPercent) {
        this.cpuUsedPercent = cpuUsedPercent;
    }

    public String getMemoryTotal() {
        return memoryTotal;
    }

    public void setMemoryTotal(String memoryTotal) {
        this.memoryTotal = memoryTotal;
    }

    public String getMemoryFree() {
        return memoryFree;
    }

    public void setMemoryFree(String memoryFree) {
        this.memoryFree = memoryFree;
    }

    public String getMemoryUsed() {
        return memoryUsed;
    }

    public void setMemoryUsed(String memoryUsed) {
        this.memoryUsed = memoryUsed;
    }

    public String getMemoryUsedPercent() {
        return memoryUsedPercent;
    }

    public void setMemoryUsedPercent(String memoryUsedPercent) {
        this.memoryUsedPercent = memoryUsedPercent;
    }

    public String getDiskType() {
        return diskType;
    }

    public void setDiskType(String diskType) {
        this.diskType = diskType;
    }

    public String getDiskTotalSpace() {
        return diskTotalSpace;
    }

    public void setDiskTotalSpace(String diskTotalSpace) {
        this.diskTotalSpace = diskTotalSpace;
    }

    public String getDiskTotalSize() {
        return diskTotalSize;
    }

    public void setDiskTotalSize(String diskTotalSize) {
        this.diskTotalSize = diskTotalSize;
    }

    public String getDiskUsableSpace() {
        return diskUsableSpace;
    }

    public void setDiskUsableSpace(String diskUsableSpace) {
        this.diskUsableSpace = diskUsableSpace;
    }

    public String getDiskUsableSize() {
        return diskUsableSize;
    }

    public void setDiskUsableSize(String diskUsableSize) {
        this.diskUsableSize = diskUsableSize;
    }

    public String getDiskUsedSize() {
        return diskUsedSize;
    }

    public void setDiskUsedSize(String diskUsedSize) {
        this.diskUsedSize = diskUsedSize;
    }

    public String getDiskUsedPercent() {
        return diskUsedPercent;
    }

    public void setDiskUsedPercent(String diskUsedPercent) {
        this.diskUsedPercent = diskUsedPercent;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }
}
